
***********************************************************************
*Table 2: Individual fixed effects regression model on migration status 
*         and years of education
***********************************************************************

version 15.1
cd "${mypath}\CHNS_project\01_data\02_posted\"

log using "${mypath}\CHNS_project\03_log_files\06_table_2.log", replace

use CHNS_1993_2015_20_imputed.dta,clear
mi import ice, automatic

*generate exclusion condition, that is, people who work in agriculture in urban area
gen be_farmer = (migrant_group != 2 & occupation == 3 & work_unit == 4) if be_employed == 1

*assign outcome variables to the local macro
local outcome_1 "be_migrant"
local outcome_2 "year_education"

*assign key independent variables to the local macro
local inde_1 "year1997 year2000 year2004 year2006 year2009 year2011 year2015"
local inde_2 "year1997 year2000 year2004 year2006 year2009 year2011 year2015 be_migrant be_migrant##year1997 be_migrant##year2000 be_migrant##year2004 be_migrant##year2006 be_migrant##year2009 be_migrant##year2011 be_migrant##year2015"

*assign control variables to the local macro
local control_1 "age26_30 age31_35 age36_40 age41_45 age46_50 age51_55 year_education marital_status h_group1 h_group2 h_group4 h_group5 num_child num_elderly population pcgdp child_elder percent_farmer service_sector"
local control_2 "age26_30 age31_35 age36_40 age41_45 age46_50 age51_55 marital_status h_group1 h_group2 h_group4 h_group5 num_child num_elderly population pcgdp child_elder percent_farmer service_sector"

*set local path to save table             
local path "${mypath}\CHNS_project\04_tables\table_2\"

*declare imputated data as panel data
mi xtset IDind wave

*fixed-effect model for migration and years of education
quiet eststo: mi estimate,post esampvaryok: xtreg `outcome_1' `inde_1' `control_1' if time != 1 & be_farmer !=  1,fe r noomitted
est store migrantion_all,title(migrantion_all)
quiet eststo: mi estimate,post esampvaryok: xtreg `outcome_1' `inde_1' `control_1' if time != 1 & be_farmer !=  1 & degree_education <= 3,fe r noomitted
est store migrantion_low,title(migrantion_low)
quiet eststo: mi estimate,post esampvaryok: xtreg `outcome_1' `inde_1' `control_1' if time != 1 & be_farmer !=  1 & degree_education > 3,fe r noomitted
est store migrantion_high,title(migrantion_high)
quiet eststo: mi estimate,post esampvaryok: xtreg `outcome_2' `inde_2' `control_2' if be_rural_resident == 0 & time != 1 & be_farmer !=  1,fe r noomitted
est store education_all,title(education_all)
quiet eststo: mi estimate,post esampvaryok: xtreg `outcome_2' `inde_2' `control_2' if be_rural_resident == 0 & time != 1 & be_farmer !=  1 & degree_education <= 3,fe r noomitted
est store education_low,title(education_low)
quiet eststo: mi estimate,post esampvaryok: xtreg `outcome_2' `inde_2' `control_2' if be_rural_resident == 0 & time != 1 & be_farmer !=  1 & degree_education > 3,fe r noomitted
est store education_high,title(education_high)
esttab migrantion_all migrantion_low migrantion_high education_all education_low education_high using "`path'table2.csv", constant b(3) star(+ 0.10 * 0.05 ** 0.01) se(%9.3f) r2 replace nogap nonumbers noomitted stats(N_mi)

log close
